﻿var loveHouseModule = angular.module('loveHouseModule', []);
loveHouseModule.controller("loveHouseCtrl", ['$scope', '$interval', '$stateParams', function($scope, $interval, $stateParams) {
	$scope.wedOfName = $stateParams.wedOfName; //谁的请柬 
	$scope.islh_dec = false;
	var pregNum = 0;
	var loveWorldNmu1 = 0;
	var loveWorldNmu2 = 0;
	var vm = 0;
	var MarryNum = 0;
	var newNum = 0;
	var meetNum = 0;
	var recallNum = 0;
	var travelNum = 0;
	var familyNum = 0;
	
	//		打开以及关闭爱情小屋说明弹窗
	$scope.openLhExp = function() {
		$scope.islh_dec = true;
	}
	$scope.closeLhExp = function() {
		$scope.islh_dec = false;
	}


//	$(function() {
//		
////		console.log(document.width())
//	});
	
	$(document).ready(function(){
		
		
		
		$(".gift_item")[0].style.border = "5px solid #feacad"; //设置礼物窗口打开时的边框		
		let loveHeightH=$(document.body).width()/(414/403)-10;
		let loveHeightF=$(document.body).height()-$(document.body).width()/(414/403);
		$('.loveHouseHeader').css({'width':$(document.body).width()+"px",'height':loveHeightH+'px'})		
		$('.loveHouseFooter').css({'height':loveHeightF+"px",'top':loveHeightH+"px"})

})
	
	
	
	$scope.DIYMsgS = function() {
		$scope.sendMsgNum++;
		let myDate = new Date();
		let NewDate = myDate.getFullYear() + "-" + myDate.getYear() + "-" + myDate.getDate();
		let NewHours = myDate.getHours() + ":" + myDate.getMinutes();
		$scope.randomNum = parseInt(Math.random() * 13 + 1);
		if($scope.MyDIYMsg != undefined) {
			console.log($('.input_diyMsg').val())
			$scope.MsgArray.push({
				userImg: $scope.userImg,
				userName: $scope.userName,
				randomNum: $scope.randomNum,
				txt: $scope.MyDIYMsg,
				isemoji_img: false
			})
			$scope.LHrecord.push({
				recordTime: NewDate,
				userImg: $scope.userImg,
				userName: $scope.userName,
				txt: $scope.MyDIYMsg,
				recordHours: NewHours,
				isRecord: true,
				isemoji_img: false
			});
			$scope.BarMsg.push({
				userName: $scope.userName,
				txt: $scope.MyDIYMsg,
				isemoji_img: false
			})
			$scope.isDanmaku = true;
			$('.input_diyMsg').val("");
		}
		if($scope.sendMsgNum < 4) {
			$scope.upgrade(1);
		}
	}
	// S 男猪脚与女猪脚动画
	var loveWorld1 = $interval(function() {
		if(loveWorldNmu1 % 2 == 0) {
			$(".loveHouse_boyEye").attr("src", "images/index/loveHouse/loveHouse1/loveHouse_boyEye.png")
			loveWorldNmu1++;
		} else {
			$(".loveHouse_boyEye").attr("src", "images/index/loveHouse/loveHouse1/loveHouse_boyEye2.png")
			loveWorldNmu1++;
		}
	}, 2000);
	var loveWorld2 = $interval(function() {
		if(loveWorldNmu2 % 2 == 0) {
			$(".loveHouse_girlEye1").attr("src", "images/index/loveHouse/loveHouse1/loveHouse_girlEye.png");
			$(".loveHouse_girlEye2").attr("src", "images/index/loveHouse/loveHouse1/loveHouse_girlEye.png");
			$(".loveHouse_girlEye1").css("width", "3.5%");
			$(".loveHouse_girlEye2").css("width", "3.5%");
			$(".loveHouse_mouth").attr("src", "images/index/loveHouse/loveHouse1/loveHouse_mouth1.png")
			$(".loveHouse_mouth").css({ "width": "2%", "left": "53%" });
			loveWorldNmu2++;
		} else {
			$(".loveHouse_girlEye1").attr("src", "images/index/loveHouse/loveHouse1/loveHouse_girlEye1.png")
			$(".loveHouse_girlEye2").attr("src", "images/index/loveHouse/loveHouse1/loveHouse_girlEye2.png")
			$(".loveHouse_mouth").attr("src", "images/index/loveHouse/loveHouse1/loveHouse_mouth2.png")
			$(".loveHouse_girlEye1").css("width", "4.5%");
			$(".loveHouse_girlEye2").css("width", "4.5%");
			$(".loveHouse_mouth").css({ "width": "2.5%","left": "53%" })
			$(".loveHouse_mouth").attr("src", "images/index/loveHouse/loveHouse1/loveHouse_mouth1.png")
			loveWorldNmu2++;
		}
	}, 1500);

	var pregNan = $interval(function() {
		if(pregNum % 2 == 0) {

			//怀孕场景男猪脚	
			$(".pregNan_boy_eye").attr("src", "images/index/loveHouse/pregNan/pregNan_boy_eye.png");
			$(".pregNan_boy_eye").css({ "width": '4%', 'top': '78%' });
			$(".pregNan_girl_eye").attr("src", "images/index/loveHouse/pregNan/pregNan_girl_eye.png");
			$(".pregNan_girl_eye").css("width", '17%');

			pregNum++;
		} else {
			//怀孕场景男猪脚	
			$(".pregNan_boy_eye").attr("src", "images/index/loveHouse/pregNan/pregNan_boy_eye2.png");
			$(".pregNan_boy_eye").css({ "width": "3%", "top": "79%" });
			$(".pregNan_girl_eye").attr("src", "images/index/loveHouse/pregNan/pregNan_girl_eye2.png");
			$(".pregNan_girl_eye").css("width", '16%');

			pregNum++;

		}
	}, 1500);

	var MarryScene = $interval(function() {
		if(MarryNum % 2 == 0) {
			$(".MarryScene_speak1").attr("src", "images/index/loveHouse/MarryScene/MarryScene_speak2.png");
			$(".MarryScene_speak2").attr("src", "images/index/loveHouse/MarryScene/MarryScene_speak2.png");
			$(".MarryScene_speak3").attr("src", "images/index/loveHouse/MarryScene/MarryScene_speak4.png");
			//男配角动画
			$(".MarryScene_Boy_eye1").attr("src", "images/index/loveHouse/MarryScene/MarryScene_Boy_eye1.png");
			$(".MarryScene_Boy_eye2").attr("src", "images/index/loveHouse/MarryScene/MarryScene_Boy_eye1.png");

			$(".MarryScene_speak6").css('width', '2%');
			//女配角动画
			$(".MarryScene_girl_eye1").attr("src", "images/index/loveHouse/MarryScene/MarryScene_girl_eye1.png");
			$(".MarryScene_girl_eye2").attr("src", "images/index/loveHouse/MarryScene/MarryScene_girl_eye1.png");
			MarryNum++;
		} else {
			$(".MarryScene_speak1").attr("src", "images/index/loveHouse/MarryScene/MarryScene_speak1.png");
			$(".MarryScene_speak2").attr("src", "images/index/loveHouse/MarryScene/MarryScene_speak1.png");
			$(".MarryScene_speak3").attr("src", "images/index/loveHouse/MarryScene/MarryScene_speak3.png");
			//男配角动画
			$(".MarryScene_Boy_eye1").attr("src", "images/index/loveHouse/MarryScene/MarryScene_Boy_eye2.png");
			$(".MarryScene_Boy_eye2").attr("src", "images/index/loveHouse/MarryScene/MarryScene_Boy_eye2.png");

			//女配角动画
			$(".MarryScene_girl_eye1").attr("src", "images/index/loveHouse/MarryScene/MarryScene_girl_eye2.png");
			$(".MarryScene_girl_eye2").attr("src", "images/index/loveHouse/MarryScene/MarryScene_girl_eye3.png");
			MarryNum++;
		}
	}, 500)
	var newLift = $interval(function() {
		if(newNum % 2 == 0) {
			$(".newLife_gril_eye").attr("src", "images/index/loveHouse/newLife/newLife_gril_eye1.png");
			$(".newLife_gril_eye").css('top', '55%');
			$(".meetPar_Ded_mouth").attr("src", "images/index/loveHouse/meetPar/meetPar_Ded_mouth1.png");
			$(".meetPar_boy_mouth").attr("src", "images/index/loveHouse/meetPar/meetPar_boy_mouth2.png");

			newNum++;
		} else {
			$(".newLife_gril_eye").attr("src", "images/index/loveHouse/newLife/newLife_gril_eye2.png");
			$(".newLife_gril_eye").css('top', '55.5%');
			$(".meetPar_Ded_mouth").attr("src", "images/index/loveHouse/meetPar/meetPar_Ded_mouth2.png");
			$(".meetPar_boy_mouth").attr("src", "images/index/loveHouse/meetPar/meetPar_boy_mouth1.png");
			newNum++;
		}

	}, 1500)

	var meetPar = $interval(function() {
		if(meetNum % 2 == 0) {

			//			$(".meetPar_Mom").attr("src", "images/index/loveHouse/meetPar/meetPar_Mom.png");	
			//			$(".meetPar_boy").attr("src", "images/index/loveHouse/meetPar/meetPar_boy.png");	
			//			$(".meetPar_girl").attr("src", "images/index/loveHouse/meetPar/meetPar_girl.png");	

			meetNum++;

		} else {

			//			$(".meetPar_Ded_mouth").attr("src", "images/index/loveHouse/meetPar/meetPar_Ded_mouth2.png");	
			//			$(".meetPar_Mom").attr("src", "images/index/loveHouse/meetPar/meetPar_Mom2.png");	
			//			$(".meetPar_boy").attr("src", "images/index/loveHouse/meetPar/meetPar_boy2.png");	
			//			$(".meetPar_girl").attr("src", "images/index/loveHouse/meetPar/meetPar_girl2.png");	

			meetNum++;

		}
	}, 1000);

	var recall = $interval(function() {
		if(recallNum % 2 == 0) {
			$("#recall_girl_eye").css("top", "38.5%");
			$("#recall_girl_eye").attr("src", "images/index/loveHouse/recall/recall_girl_eye2.png");
			$("#recall_boy_eye").attr("src", "images/index/loveHouse/recall/recall_boy_eye2.png");
			$("#recall_child_eye").attr("src", "images/index/loveHouse/recall/recall_child_eye2.png");
			$("#family_mouth").attr("src", "images/index/loveHouse/family/family_mouth1.png");

			recallNum++;

		} else {
			$("#recall_girl_eye").css("top", "37%");
			$("#recall_girl_eye").attr("src", "images/index/loveHouse/recall/recall_girl_eye1.png");
			$("#recall_boy_eye").attr("src", "images/index/loveHouse/recall/recall_boy_eye1.png");
			$("#recall_child_eye").attr("src", "images/index/loveHouse/recall/recall_child_eye1.png");
			$("#family_mouth").attr("src", "images/index/loveHouse/family/family_mouth2.png");
			recallNum++;

		}
	}, 2000);
	var travel = $interval(function() {
		if(travelNum % 2 == 0) {
			$("#travel_child_eye").attr("src", "images/index/loveHouse/travel/travel_child_eye1.png");

			travelNum++;

		} else {
			$("#travel_child_eye").attr("src", "images/index/loveHouse/travel/travel_child_eye2.png");
			travelNum++;

		}
	}, 1000);

	var family = $interval(function() {
		if(familyNum % 2 == 0) {
			$("#family_girl_eye").attr("src", "images/index/loveHouse/family/family_girl_eye1.png");

			familyNum++;

		} else {
			$("#family_girl_eye").attr("src", "images/index/loveHouse/family/family_girl_eye2.png");

			familyNum++;

		}
	}, 1000);
	$scope.$on('$destroy', function() {

		$interval.cancel(loveWorld1);
		$interval.cancel(loveWorld2);
		$interval.cancel(pregNan);
		$interval.cancel(MarryScene);
		$interval.cancel(newLift);
		$interval.cancel(meetPar);
		$interval.cancel(recall);
		$interval.cancel(travel);
		$interval.cancel(family);

	})
	// 男猪脚与女猪脚动画 E 

	if($(document).width() < 375) {
		//			console.log($(document).width())
		$(".loveHouse_ladle").css({ "top": "73.5%", "left": "39%" })

	}
	var u = navigator.userAgent;
	if(u.indexOf('Android') > -1 || u.indexOf('Linux') > -1) { //安卓手机
		console.log("安卓手机");
		if($(document).width() <= 370) {
			$(".loveHouseGirl").css('width', '34%');
			$(".loveHouse_ladle").css({ "top": "74.5%", "left": "39%" });
			$(".loveHouse_girlEye1").css({ "top": "64.5%", "left": "47.5%" });
			$(".loveHouse_girlEye2").css({ "top": "64%", "left": "56%" });
			$(".loveHouse_mouth").css({ "top": "69%", "left": "51%" });
		}
	} else if(u.indexOf('iPhone') > -1) { //苹果手机
		// window.location.href = "mobile/index.html";
		console.log("苹果手机");
	} else if(u.indexOf('Windows Phone') > -1) { //winphone手机
		console.log("winphone手机");
		// window.location.href = "mobile/index.html";
	}

}])